package data;

import models.AutoSite;
import models.Blog;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

public class BlogData {
	private static Objectify ofy;
	
	public static void insert(Blog blog) {
		init();
		ofy.put(blog);
	}
	
	public static Blog getById(String blogId) {
		init();
		Blog blog  = new Blog();
		try {
			blog = ofy.get(new Key<Blog>(Blog.class, blogId));
		} catch (Exception e) {
			blog = null;
		}
		return blog;
	}
	
	private static void init() {
		try {
			ObjectifyService.register(Blog.class);
		} catch (Exception e) {
			//e.printStackTrace();
		}
		ofy = ObjectifyService.begin();
	}
}
